package com.pay.sdk.example;

import java.text.SimpleDateFormat;
import java.util.Date;

import com.pay.sdk.service.channel2.ChanneTwolPay;
/**
 * 通道2 扫码、条码 H5 代码示例
 * @author Administrator
 *
 */
public class Channel2Example {

	public static void main(String[] args) {
        System.out.println("==重要== 调用任何API前，请先配置Configure类");
      //使用测试环境，生产上使用请设置为false
        scanPayExample();
//        	scanPayQueryExample();
//    	  payOtherExample();	//单笔代付
//        payOtherQueryExample(); //单笔代付结果查询
//        bankTypeQueryExample(); //联行号查询
//        h5PayExample();
//        barPayExample();
//          orderSyncExample();
    }
	
	 /**
     * 扫码支付（支付宝、微信、qq钱包）
     * @throws  
     */
    public static void scanPayExample(){
    	try {
    		String out_trade_no = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
        	String total_fee = "1"; //单位分
        	String body = "微信测试";
        	String device_info = "PC";
        	String time_expire = "1440";
        	String acquirer_type = "wechat";
        	String bank_card_limit = "1";//支付卡类型：1-储蓄卡 2储蓄卡和信用卡
        	String notify_url = "http://paytest.shopping98.com/pay/apiNotify.shtml";
        	String attach = "sOpenId=2831486693613247347563";
        	String result = ChanneTwolPay.scanPay(out_trade_no, total_fee, body, device_info,notify_url,acquirer_type,bank_card_limit,time_expire,attach);
        	System.out.println("微信扫码支付："+result);
		} catch (Exception e) {
			e.printStackTrace();
		}
    }
    /**
     * h5支付
     * @throws  
     */
    public static void h5PayExample(){
    	try {
    		String out_trade_no = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
    		String total_fee = "1"; //单位分
    		String body = "H5支付测试";
    		String device_info = "PC";
    		String time_expire = "1440";
    		String acquirer_type = "wechat";
    		String bank_card_limit = "2";//支付卡类型：1-储蓄卡 2储蓄卡和信用卡
    		String notify_url = "http://paytest.shopping98.com/pay/apiNotify.shtml";
    		String appId = "wxd1732e33689bd7d4";
    		String openid = "oM4YVs6DpFBXteF3MBZEu31c5aDU";
    		String result = ChanneTwolPay.h5Pay(out_trade_no, total_fee, body, device_info, notify_url, acquirer_type, bank_card_limit, time_expire, appId, openid);
    		System.out.println("微信扫码支付："+result);
    	} catch (Exception e) {
    		e.printStackTrace();
    	}
    }
    
    
    /**
     * 行扫码支付（支付宝、微信）
     * @throws  
     */
    public static void scanPayQueryExample(){
    	try {
    		String out_trade_no = "";
    		String transation_id = "";
    		String out_transation_id = "";
        	String result = ChanneTwolPay.payQuery(out_trade_no, transation_id, out_transation_id);
        	System.out.println("微信扫码支付："+result);
		} catch (Exception e) {
			e.printStackTrace();
		}
    }
    
    
    /**
     * 单笔代付
     * @param user_order_no 用户订单号
     * @param amount  金额（单位:元）
     * @param account_type 00-银行卡 01-存折。不填时默认银行卡00
     * @param account_no 账号
     * @param account_name 开户名
     * @param id_type  证件类型 0:身份证 1：户口簿 2：护照 3：军官证 4:士兵证 5：港澳居民来往内地通行证 6:台湾同胞来往内地通行证 7：临时身份证 8:外国人居留证 9：警官证 X:其他证件
     * @param id  证件号
     * @param tel 电话号码
     * @param bank_code 银行编码
     *  @param account_prop 0-私人 1-公司 ，不填时默认为0-私人
     * @return json格式结果，返回结果包含字段请参看文档
     */
    public static void payOtherExample(){
    	try {
    		String user_order_no =  new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
    		String amount = "2.1";
    		String account_type = "00";
    		String account_name = "杨学勇";//账号名
    		String account_no = "6228480089507246372";//账号
    		String id_type = "0";
    		String id = "522631198702280017";//身份证
    		String tel = "18200982382";
    		String bank_code = "103";
    		String bank_type = "";//联行号
    		String account_prop = "0";
        	String result = ChanneTwolPay.payOther(user_order_no, amount, account_type, account_name, account_no, id_type, id, tel, bank_code,account_prop,bank_type);
        	System.out.println("单笔代付："+result);
		} catch (Exception e) {
			e.printStackTrace();
		}
    }
    
    
    
    /**
     * 代付查询
     * @param query_sn 查询交易流水
     * @param user_order_no 用户订单号 二选一
     * @return
     */
    public static void payOtherQueryExample(){
    	try {
    		String query_sn = "562792492338262016";
    		String user_order_no = "20161107151445";
        	String result = ChanneTwolPay.payOtherQuery(query_sn, user_order_no);
        	System.out.println("代付查询："+result);
		} catch (Exception e) {
			e.printStackTrace();
		}
    }
    
    
    /**
     * 条码支付（支付宝、微信）
     * @throws  
     */
    public static void barPayExample(){
    	try {
    		String out_trade_no = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
        	String total_fee = "1"; //单位分
        	String body = "订单号："+out_trade_no;
        	String device_info = "PC";
        	String time_expire = "1440";
        	String auth_code = "130344136174206914";
        	String acquirer_type = "wechat";
        	String bank_card_limit = "1";//支付卡类型：1-储蓄卡 2储蓄卡和信用卡
        	String notify_url = "http://paytest.shopping98.com/pay/apiNotify.shtml";
        	String attach = "sOpenId=2831486693613247347563";
        	String result = ChanneTwolPay.barPay(out_trade_no, total_fee, body, auth_code, device_info, acquirer_type, bank_card_limit, time_expire, attach);
        	System.out.println("银行条码支付："+result);
		} catch (Exception e) {
			e.printStackTrace();
		}
    }
    
    
    
    /**
     * 代付银行联行号查询
     * @param bank_code 银行编码
     * @param province  开户省份
     * @param city  开户城市
     * @param branch_name 开户网点关键字
     * @return
     */
    public static void bankTypeQueryExample(){
    	try {
    		String bank_code = "102";
    		String province = "广东";
    		String city = "广州";
    		String branch_name = "天河";
        	String result = ChanneTwolPay.bankTypeQuery(bank_code, province, city, branch_name);
        	System.out.println("代付查询："+result);
		} catch (Exception e) {
			e.printStackTrace();
		}
    }
    
    /**	
     * 订单同步
     */
    public static void orderSyncExample(){
    	try {
    		String transaction_id = "614225155691405312";
        	String result = ChanneTwolPay.orderSync(transaction_id);
        	System.out.println("订单同步："+result);
		} catch (Exception e) {
			e.printStackTrace();
		}
    }
    
    
}
